<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul{
            list-style: none;
            margin: 0;
            padding: 0;
            width: 200px;
            border: 1px solid #999;
        }
        li{
            border-bottom: 1px dashed #999;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <ul>
        <li><span><input type="checkbox" class="dsop"></span> 老友记</li>
        <li><span><input type="checkbox" class="dsop"></span> 爱情公寓</li>
        <li><span><input type="checkbox" class="dsop"></span> 请回答1988</li>
        <li><span><input type="checkbox" class="dsop"></span> 山海情</li>
        <li><span><input type="checkbox" class="dsop"></span> 还珠格格</li>
        <li><span><input type="checkbox" class="dsop"></span> 甲方乙方</li>
        <li>
            <span><input type="checkbox" class="all"> 全选</span>
            <span><input type="checkbox" class="rever"> 反选</span>
        </li>
    </ul>

    <script src="../js/jquery.js"></script>
    <script>
        // prop attr 
        $('.all').change(function(){
            $('.dsop').prop('checked', $('.all').prop('checked'))
        })

        // 检查选项，判断 全选 是否需要勾选
        function checkAll(){
            let bool = true;
            for(let i = 0;i < $('.dsop').length;i++){
                if($('.dsop').eq(i).prop('checked') == false){
                    bool = false;
                }
            }
            $('.all').prop('checked',bool)
        }

        // 给每一个选项绑定change事件
        $('.dsop').change(function(){
            checkAll();
        })

        $('.rever').change(function(){
            for(let i = 0;i < $('.dsop').length;i++){
                $('.dsop').eq(i).prop('checked',!$('.dsop').eq(i).prop('checked'));
            }
            checkAll();
        })

    </script>
</body>
</html>